{extend name="common@admin/main" /}
{block name="content"}
<div id="content">
    <div class="page-header">
        <div class="container-fluid">
            <div class="pull-right">
                <button type="submit" form="form-set" data-toggle="tooltip" title="保存" class="btn btn-primary" id="input-submit"> <i class="fa fa-save"></i>
                </button>
                <a href="" data-toggle="tooltip" title="取消" class="btn btn-default"> <i class="fa fa-reply"></i>
                </a>
            </div>
            <h1>管理员</h1>
            <ul class="breadcrumb">
                <li>
                    <a href="">首页</a>
                </li>
                <li>
                    <a href="">管理员</a>
                </li>
            </ul>
        </div>
    </div>
    <div class="container-fluid">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">
                    <i class="fa fa-pencil"></i>
                    设置管理员
                </h3>
            </div>
            <div class="panel-body">
                <!-- __ACTION__ -->
                <form action="" method="post" enctype="multipart/form-data" id="form-set" class="form-horizontal">

                    <ul class="nav nav-tabs">
                        <li class="active">
                            <a href="#tab-general" data-toggle="tab">基本信息</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="tab-general">

                            <div class="form-group">
                                <label class="col-sm-2 control-label" for="input-username">用户名</label>
                                <div class="col-sm-10">
                                    <!-- <input type="text" name="username" value="" placeholder="用户名" id="input-username" class="form-control"> -->
                                    <select name="username" id="input-username"></select>
                                </div>
                            </div>
                            
                            
                    
                            <div class="form-group">
                                <label class="col-sm-2 control-label" for="input-password_salt">角色</label>
                                <div class="col-sm-10">
                                    <div class="row">

                                    </div>
                                </div>
                            </div>


                        </div>

                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="title"}
<title>角色授权</title>
{/block}

{block name="appendJS"}
<script>
    $(function(){
        var allrole={$allrole},
            user={$user},
            back_user={$session_user};
            
            console.log(allrole)
            console.log(user)

            //角色列表
            var div=$('<div/>',{class:"col-sm-2"});   
            checkbox_list(allrole,div)

            //提交修改
            var submits=$('#input-submit');

           $("form").submit(function(e){
              e.preventDefault();
            });
           submits.click(function(){
                 var username=$(':text[name="username"]').val(),
                     role_id=$(':checkbox:checked').val();

                 var urls='/admin/addRole.json',
                     send={role_id:role_id,username:username};
                     console.log(urls)
                     console.log(send)
                   $.post(urls,send,function(res){
                         // if(res.code==1){
                         //    //跳转用户列表
                         //    location.href="/admin/permiss/userlist";
                         // }else{
                         //    alert('添加失败');
                         // }
                   });
                   return false;
              })
    }) 
 //遍历复选框
 function  checkbox_list(allrole,div){
      //遍历所有用户
      var select=$(':select[name="username"]');

      $.each(user,function(key,val){
          var option=$('<option/>',{
             value:val.id,
          }).html(val.name)  
          select.append(option);
      })

      $.each(allrole,function(key,val){
          var input=$('<input/>',{
               type:"checkbox",
               name:val,
               value:val.id,
               class:"form-control", 
               id:"input-role-"+val.id});
          var label=$('<label/>',{for:"input-role-"+val.id}).html(val.name);
        
          div.append(input).append(label);
     });
     $('.row').append(div);
 }   
</script>
{/block}
